package com.cloud.config;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Component;

/**
 * @Author: TongRui乀
 * @Date: 2019/10/9 15:48
 * @description：
 */
@Component
public class MyUserDetailService implements UserDetailsService {

    private Logger logger = LoggerFactory.getLogger(MyUserDetailService.class);

    @Autowired
    private PasswordEncoder passwordEncoder;

    @Override
    public UserDetails loadUserByUsername(String userName) throws UsernameNotFoundException {

        logger.info("用户名称:{}", userName);

        return new User("admin",
                passwordEncoder.encode("123456"),
                // 是否可用
                true,
                // 账号是否过期
                false,
                // 密码是否过期
                false,
                // 账号没有被锁定标志
                true,
                AuthorityUtils.commaSeparatedStringToAuthorityList("admin"));

    }
}
